<?php

namespace App\Services;

use App\Models\Navigation;
use App\Models\System;
use Illuminate\Database\Eloquent\Model;

class SystemService extends Model
{
    //
    const PARAMS_TYPE_SOURCE = 'source';//来源
    const PARAMS_TYPE_TAG = 'tag';//标签

    /**获取导航栏
     * @return \Illuminate\Support\Collection
     */
    public function getNavigationList()
    {
        $navigation = new Navigation();
        $navigation_parents = $navigation->getNavigationList(0);
        foreach ($navigation_parents as $k => &$v) {
            $v->children = $navigation->getNavigationList($v->id);
        }
        return $navigation_parents;
    }

    /**获取参数配置列表
     * @param $type
     * @param bool $kv
     * @return \Illuminate\Support\Collection|\stdClass
     */
    public function getParams($type, $kv = false)
    {
        $system = new System();
        $list = $system->getParams($type);
        if ($kv == false) {
            $result = new \stdClass();
            foreach ($list as $k => $v) {
                $result->{$v->key} = $v->value;
            }
            return $result;
        } else {
            return $list;
        }

    }
}
